﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;

namespace Work.Tools.Logger
{
    public class Log4netLogger : ILogger
    {
        #region Fields

        public ILog _log = null;

        #endregion

        #region Constructor

        public Log4netLogger()
        {
        }

        #endregion

        #region ILogger Interface

        public void Debug(object message)
        {
            Log.Debug(message);
        }

        public void Debug(object message, Exception exception)
        {
            Log.Debug(message, exception);
        }

        public void Error(object message)
        {
            Log.Error(message);
        }

        public void Error(object message, Exception exception)
        {
            Log.Error(message, exception);
        }

        public void Fatal(object message)
        {
            Log.Fatal(message);
        }

        public void Fatal(object message, Exception exception)
        {
            Log.Fatal(message, exception);
        }

        public void Info(object message)
        {
            Log.Info(message);
        }

        public void Info(object message, Exception exception)
        {
            Log.Info(message, exception);
        }

        public void Warn(object message)
        {
            Log.Warn(message);
        }

        public void Warn(object message, Exception exception)
        {
            Log.Warn(message, exception);
        }

        #endregion

        #region Helpers

        private ILog CreateLogger()
        {
            log4net.Config.XmlConfigurator.Configure();
            return LogManager.GetLogger(this.GetType());
        }

        private ILog Log
        {
            get
            {
                if (this._log == null)
                {
                    this._log = CreateLogger();
                }
                return this._log;
            }
        }

        #endregion

    }
}
